package Pattern.StatePattern.Program.programone;

public class Door1 {
    public final DoorState CLOSED = new DoorClosed(this);
    public final DoorState OPENING = new DoorOpening(this);
    public final DoorState OPEN = new DoorOpen(this);
    public final DoorState CLOSING = new DoorClosing(this);
    public final DoorState STAYOPEN = new DoorStayOpen(this);
    private DoorState state = CLOSED;
    //设置传输门当前状态
    public void setState(DoorState state) {
        this.state = state;
    }
    public void getState() {//根据当前状态输出对应的状态字符串
        System.out.println(state.getClass().getName());
    }
    public void click() {/*(4)*/
        state.click();
    }  //发生click事件时进行状态转换
    public void timeout() {/*(5)*/
        state.timeout();
    }  //发生timeout事件时进行状态转换
    public void complete() {/*(6)*/
        state.complete();
    }  //发生complete事件时进行状态转换
    public static void main(String[] args) {
        Door1 aDoor = new Door1();
        aDoor.getState();
        aDoor.click();
        aDoor.getState();
        aDoor.complete();
        aDoor.getState();
        aDoor.timeout();
        aDoor.getState();
        return;
    }
}

abstract class DoorState {  //定义所有状态类的基类
    protected Door1 door;
    public DoorState(Door1 door) {
        this.door = door;
    }
    public abstract void click();
    public abstract void complete();
    public abstract void timeout();
}

class DoorClosed extends DoorState { //定义一个基本的Closed状态
    public DoorClosed(Door1 door) {
        super(door);
    }
    public void click() {/*(7)*/
        new DoorOpening(door);
    }
    @Override
    public void complete() {

    }
    @Override
    public void timeout() {

    }
    //该类定义的其余代码省略
}

class DoorOpening extends DoorState {
    public DoorOpening(Door1 door) {
        super(door);
    }
    @Override
    public void click() {

    }
    @Override
    public void complete() {

    }
    @Override
    public void timeout() {

    }
}
class DoorOpen extends DoorState {
    public DoorOpen(Door1 door) {
        super(door);
    }
    @Override
    public void click() {
    }
    @Override
    public void complete() {
    }
    @Override
    public void timeout() {

    }
}
class DoorClosing extends DoorState {
    public DoorClosing(Door1 door) {
        super(door);
    }
    @Override
    public void click() {
    }
    @Override
    public void complete() {
    }
    @Override
    public void timeout() {
    }
}
class DoorStayOpen extends DoorState {
    public DoorStayOpen(Door1 door) {
        super(door);
    }
    @Override
    public void click() {
    }
    @Override
    public void complete() {
    }
    @Override
    public void timeout() {

    }
}
//其余代码省略
